#include <cassert>

#include "World.hpp"
#include "camera/Camera.hpp"
#include "light/Light.hpp"

int World::LEVEL_SIZE = 100;

World::World(std::string aName) : GameObject(aName), selectedAsteroid(NULL) {
    tree = new Octree(1, glm::vec3(0, 0, 0), LEVEL_SIZE / 2);
    asteroids=0;
}

World::~World() {
    //dtor
}

void World::accept(Visitor* visitor) {
    visitor->visit(this);
}

Camera* World::getCamera() {
    return camera;
}

Player* World::getPlayer() {
    return player;
}

//Store all objects that are being made from the level builder
void World::add(GameObject* child) {
    assert(child != NULL);

    children.push_back(child);
}

//Get a specific child.
GameObject* World::getChild(std::string child) {
    std::vector<GameObject*>* childs = getChildren();

    for(std::vector<GameObject*>::iterator i = childs->begin(); i != childs->end(); ++i) {
        unsigned found = (*i)->getName().find(child);

        if(found != std::string::npos) {
            return (*i);
        }
    }

    return NULL;
}

Octree* World::getTree() {
    return tree;
}

int World::getAsteroidsLeft() {
    return asteroids;
}

void World::setAsteroidsLeft(int num) {
    asteroids = num;
}
